package com.oocl.mock.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.mock.pojo.Customer;
import com.oocl.mock.service.CustomerManager;

public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CustomerManager manager;
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String uname = request.getParameter("cname");
		String psd = request.getParameter("password");
		
		if("".equals(uname.trim()) || "".equals(psd.trim())){
			request.setAttribute("error", "用户名或者密码为空");
			request.getRequestDispatcher("login.jsp").forward(request, response);
			return;
		}
		
		Customer customer = manager.findCustomerByName(uname);
		if(null==customer){
			request.setAttribute("error", "用户名不存在");
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("success.jsp").forward(request, response);
		}
		
	}

}
